<?php
class BitMask 
{
	public function setOn($current_int_value,$bit_num)
	{
		return $this->switcher($current_int_value,$bit_num,"1");
	}
	
	public function setOff($current_int_value,$bit_num)
	{
		return $this->switcher($current_int_value,$bit_num,"0");
	}
	
	private function switcher($current_int_value,$bit_num,$bit_value)
	{
		//$bin_str = decbin($current_int_value);
		
		$current_bit_value = $this->bitValue($current_int_value,$bit_num);
		if ($current_bit_value==$bit_value) return $current_int_value;
		
		$check_mask = $this->makeBitMask($bit_num);
		return $current_int_value ^ $check_mask;
		
	}
	
	public function bitValue($current_int_value,$bit_num)
	{
		$check_mask = $this->makeBitMask($bit_num);
		return ($current_int_value & $check_mask) == $check_mask ? 1 : 0;
	}
	
	public function makeBitMask($bit_num)
	{
		return bindec(str_pad("1",$bit_num--,"0"));
	}
	
}
?>